<template>
    <a-flex justify="space-between" align="center">
      <a-menu v-model:selectedKeys="current" mode="horizontal" :items="items"/>
      <a-flex  align="center">
        <a-popconfirm
            title="服务将重载配置重新启动，是否确认重启?"
            ok-text="确认"
            cancel-text="取消"
            @confirm="confirm"
        >
          <a-button type="link">重启服务</a-button>
        </a-popconfirm>
        <a-button type="link" @click="exitSys" danger>退出</a-button>
      </a-flex>
    </a-flex>
  <a-card size="small" :bordered="false">
    <data-rule v-if="'data-rule' == current"></data-rule>
    <register-config v-else-if="'register-config' == current"></register-config>
    <register-data v-else-if="'register-data' == current"></register-data>
    <forward-data v-else-if="'forward-data' == current"></forward-data>
    <forward-config v-else-if="'forward-config' == current"></forward-config>
    <mqtt-config v-else-if="'mqtt' == current"></mqtt-config>
    <slave-data v-else-if="'forward-slave-data' == current"></slave-data>
    <slave-config v-else-if="'forward-slave-config' == current"></slave-config>
    <a-empty v-else description="暂未开发"></a-empty>
  </a-card>
</template>

<script setup>
import {ref} from "vue";
import DataRule from "@/components/dataRule.vue";
import RegisterConfig from "@/components/register/registerConfig.vue";
import RegisterData from "@/components/register/registerData.vue";
import forwardData from "@/components/forward/forwardData.vue";
import ForwardConfig from "@/components/forward/forwardConfig.vue";
import MqttConfig from "@/components/mqtt/mqttConfig.vue"
import {message} from "ant-design-vue";
import {baseRequest} from "@/utils/request.js";
import {useRouter} from "vue-router";
import SlaveData from "@/components/slave/SlaveData.vue";
import SlaveConfig from "@/components/slave/SlaveConfig.vue";
const router = useRouter();
const current = ref(['register-data']);
const items = ref([
  {
    key: 'data-rule',
    label: '数据规则'
  },
  {
    key: 'register',
    label: 'Modbus数据采集',
    children: [
      {
        key: 'register-data',
        label: '采集数据'
      },
      {
        key: 'register-config',
        label: '采集配置'
      }
    ]
  },
  {
    key: 'forward-slave',
    label: 'Modbus模拟从站',
    children: [
      {
        key: 'forward-slave-data',
        label: '从站数据'
      },
      {
        key: 'forward-slave-config',
        label: '从站配置'
      }
    ]
  },
  {
    key: 'forward',
    label: 'IEC-104数据转发',
    children: [
      {
        key: 'forward-data',
        label: '转发数据'
      },
      {
        key: 'forward-config',
        label: '转发配置'
      }
    ]
  },
  {
    key: 'mqtt',
    label: 'MQTT'
  },
]);
const confirm = e => {
  baseRequest("/config/restart", {},'post').then(res => {
    if(res.data.code == 200){
      message.success("重启成功")
    }else {
      message.error(res.data.message)
    }
  })
};
const exitSys = ()=>{
  router.push("/login")
}
</script>


<style scoped>

</style>
